#coding=utf-8
#Boa:FramePanel:PanelReportProduct

import wx

from MyListCtrl import MyListCtrlSaleProductReport

[wxID_PANELREPORTPRODUCT, wxID_PANELREPORTPRODUCTBTNALLDATE, 
 wxID_PANELREPORTPRODUCTBTNDAYAFTER, wxID_PANELREPORTPRODUCTBTNDAYBEFORE, 
 wxID_PANELREPORTPRODUCTBTNONEDAY, wxID_PANELREPORTPRODUCTBTNONEMONTH, 
 wxID_PANELREPORTPRODUCTBTNONEWEEK, wxID_PANELREPORTPRODUCTBTNONEYEAR, 
 wxID_PANELREPORTPRODUCTBTNSEARCH, wxID_PANELREPORTPRODUCTDATEEND, 
 wxID_PANELREPORTPRODUCTDATESTART, wxID_PANELREPORTPRODUCTSTATICTEXT1, 
 wxID_PANELREPORTPRODUCTTCQUERY, wxID_PANELREPORTPRODUCTTDATE, 
 wxID_PANELREPORTPRODUCTTPEER, 
] = [wx.NewId() for _init_ctrls in range(15)]

class PanelReportProduct(wx.Panel):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Panel.__init__(self, id=wxID_PANELREPORTPRODUCT,
              name=u'PanelReportProduct', parent=prnt, pos=wx.Point(346, 119),
              size=wx.Size(933, 652), style=wx.TAB_TRAVERSAL)
        self.SetClientSize(wx.Size(925, 618))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False, u'Arial'))
        self.SetBackgroundColour(wx.Colour(183, 209, 173))

        self.TDate = wx.StaticText(id=wxID_PANELREPORTPRODUCTTDATE,
              label=u'\u67e5\u8be2\u65e5\u671f\uff1a', name=u'TDate',
              parent=self, pos=wx.Point(22, 38), size=wx.Size(85, 19), style=0)
        self.TDate.SetAutoLayout(True)
        self.TDate.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'Arial'))

        self.dateStart = wx.DatePickerCtrl(id=wxID_PANELREPORTPRODUCTDATESTART,
              name=u'dateStart', parent=self, pos=wx.Point(126, 30),
              size=wx.Size(120, 27), style=wx.DP_DROPDOWN)
        self.dateStart.SetLabel(u'2014-04-24')
        self.dateStart.SetValue(wx.DateTimeFromDMY(24, 3, 2014, 0, 0, 0))
        self.dateStart.SetToolTipString(u'dateStart')

        self.staticText1 = wx.StaticText(id=wxID_PANELREPORTPRODUCTSTATICTEXT1,
              label=u'\u81f3', name='staticText1', parent=self,
              pos=wx.Point(254, 38), size=wx.Size(18, 18), style=0)

        self.dateEnd = wx.DatePickerCtrl(id=wxID_PANELREPORTPRODUCTDATEEND,
              name=u'dateEnd', parent=self, pos=wx.Point(278, 30),
              size=wx.Size(116, 27), style=wx.DP_DROPDOWN)

        self.btnOneDay = wx.Button(id=wxID_PANELREPORTPRODUCTBTNONEDAY,
              label=u'\u5f53\u65e5', name=u'btnOneDay', parent=self,
              pos=wx.Point(402, 30), size=wx.Size(46, 29), style=0)
        self.btnOneDay.Bind(wx.EVT_BUTTON, self.OnBtnOneDayButton,
              id=wxID_PANELREPORTPRODUCTBTNONEDAY)

        self.btnOneWeek = wx.Button(id=wxID_PANELREPORTPRODUCTBTNONEWEEK,
              label=u'\u4e00\u5468', name=u'btnOneWeek', parent=self,
              pos=wx.Point(450, 30), size=wx.Size(46, 29), style=0)
        self.btnOneWeek.Bind(wx.EVT_BUTTON, self.OnBtnOneWeekButton,
              id=wxID_PANELREPORTPRODUCTBTNONEWEEK)

        self.btnOneMonth = wx.Button(id=wxID_PANELREPORTPRODUCTBTNONEMONTH,
              label=u'\u4e00\u6708', name=u'btnOneMonth', parent=self,
              pos=wx.Point(498, 30), size=wx.Size(46, 29), style=0)
        self.btnOneMonth.Bind(wx.EVT_BUTTON, self.OnBtnOneMonthButton,
              id=wxID_PANELREPORTPRODUCTBTNONEMONTH)

        self.btnOneYear = wx.Button(id=wxID_PANELREPORTPRODUCTBTNONEYEAR,
              label=u'\u4e00\u5e74', name=u'btnOneYear', parent=self,
              pos=wx.Point(546, 30), size=wx.Size(46, 29), style=0)
        self.btnOneYear.Bind(wx.EVT_BUTTON, self.OnBtnOneYearButton,
              id=wxID_PANELREPORTPRODUCTBTNONEYEAR)

        self.btnAllDate = wx.Button(id=wxID_PANELREPORTPRODUCTBTNALLDATE,
              label=u'\u5168\u90e8', name=u'btnAllDate', parent=self,
              pos=wx.Point(594, 30), size=wx.Size(46, 29), style=0)
        self.btnAllDate.Bind(wx.EVT_BUTTON, self.OnBtnAllDateButton,
              id=wxID_PANELREPORTPRODUCTBTNALLDATE)

        self.btnDayBefore = wx.Button(id=wxID_PANELREPORTPRODUCTBTNDAYBEFORE,
              label=u'\u524d\u4e00\u5929', name=u'btnDayBefore', parent=self,
              pos=wx.Point(656, 30), size=wx.Size(64, 29), style=0)
        self.btnDayBefore.Bind(wx.EVT_BUTTON, self.OnBtnDayBeforeButton,
              id=wxID_PANELREPORTPRODUCTBTNDAYBEFORE)

        self.btnDayAfter = wx.Button(id=wxID_PANELREPORTPRODUCTBTNDAYAFTER,
              label=u'\u540e\u4e00\u5929', name=u'btnDayAfter', parent=self,
              pos=wx.Point(720, 30), size=wx.Size(64, 29), style=0)
        self.btnDayAfter.Bind(wx.EVT_BUTTON, self.OnBtnDayAfterButton,
              id=wxID_PANELREPORTPRODUCTBTNDAYAFTER)

        self.tcQuery = wx.TextCtrl(id=wxID_PANELREPORTPRODUCTTCQUERY,
              name=u'tcQuery', parent=self, pos=wx.Point(126, 64),
              size=wx.Size(266, 28), style=0, value=u'')

        self.btnSearch = wx.Button(id=wxID_PANELREPORTPRODUCTBTNSEARCH,
              label=u'\u67e5\u8be2', name=u'btnSearch', parent=self,
              pos=wx.Point(408, 64), size=wx.Size(72, 29), style=0)
        self.btnSearch.Bind(wx.EVT_BUTTON, self.OnBtnSearchButton,
              id=wxID_PANELREPORTPRODUCTBTNSEARCH)

        self.TPeer = wx.StaticText(id=wxID_PANELREPORTPRODUCTTPEER,
              label=u'\u5355\u4f4d\u540d\u79f0\uff1a', name=u'TPeer',
              parent=self, pos=wx.Point(22, 70), size=wx.Size(85, 19), style=0)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self.myInit()
    
    def myInit(self):
        self.dateStart.SetValue(wx.DateTime.Today())
        self.dateEnd.SetValue(wx.DateTime.Today())
        
        self.lc = MyListCtrlSaleProductReport(self)
        self.lc.SetSize(wx.Size(850, 450))
        self.lc.Move(wx.Point(22,100))

    def OnBtnOneDayButton(self, event):
        self.dateStart.SetValue(wx.DateTime.Today())
        self.dateEnd.SetValue(wx.DateTime.Today())

    def OnBtnOneWeekButton(self, event):
        day = wx.DateTime.Today()
        self.dateEnd.SetValue(day)
        
        span = wx.DateSpan.Days(7)
        day.SubtractDS(span)
        self.dateStart.SetValue(day)
        

    def OnBtnOneMonthButton(self, event):
        day = wx.DateTime.Today()
        self.dateEnd.SetValue(day)
        
        span = wx.DateSpan.Months(1)
        day.SubtractDS(span)
        self.dateStart.SetValue(day)

    def OnBtnOneYearButton(self, event):
        day = wx.DateTime.Today()
        self.dateEnd.SetValue(day)
        
        span = wx.DateSpan.Years(1)
        day.SubtractDS(span)
        self.dateStart.SetValue(day)

    def OnBtnAllDateButton(self, event):
        self.dateEnd.SetValue(wx.DateTime.Today())        
        self.dateStart.SetValue(wx.DateTimeFromDMY(1,0,2000,0,0,00))

    def OnBtnDayBeforeButton(self, event):
        day = self.dateEnd.GetValue()        
        span = wx.DateSpan.Days(1)
        day.SubtractDS(span)
        self.dateEnd.SetValue(day)
        self.dateStart.SetValue(day)

    def OnBtnDayAfterButton(self, event):
        day = self.dateEnd.GetValue()        
        span = wx.DateSpan.Days(1)
        day.AddDS(span)
        self.dateEnd.SetValue(day)
        self.dateStart.SetValue(day)

    def OnBtnSearchButton(self, event):
        filter = {'dateStart':self.dateStart.GetValue().Format('%Y-%m-%d'),
                    'dateEnd':self.dateEnd.GetValue().Format('%Y-%m-%d'),
                    'query':self.tcQuery.GetValue()}
        
        cnt = self.lc.refresh(filter)
        if (cnt == 0):
            dlg = wx.MessageDialog(self, u'没有符合条件的记录', u'提示消息', wx.OK|wx.ICON_INFORMATION)
            dlg.ShowModal()
